package com.myworld.web;

import com.myworld.service.impl.FileBigUploadService;
import com.myworld.vo.response.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zhuqiang
 * @ClassName: FileUploadContorller
 * @Description:大文件上传
 * @date 2018年12月25日 下午2:40:21
 */
@RestController
@RequestMapping("/bigFile")
public class FileBigUploadController {
    Logger logger= LoggerFactory.getLogger(FileBigUploadController.class);

    @Autowired
    private FileBigUploadService fileBigUploadService;

    /**
     * 文件上传注册
     * @param fileMd5
     * @param fileName
     * @param fileSize
     * @param mimetype
     * @param fileExt 文件扩展名
     * @return
     */
    @PostMapping("/register")
    public Result register(String fileMd5,String fileName,Long fileSize,String mimetype,String fileExt){
        return  fileBigUploadService.register(fileMd5,fileName,fileSize,mimetype,fileExt);
    }

    /**
     * 分块检查
     * @param fileMd5
     * @param fileMd5
     * @return
     *      result:  true 分块文件存在，false 分块文件不存在
     */
    @PostMapping("/checkchunk")
    public Result checkchunk(String fileMd5,Integer chunk,Integer chunkSize){
        return fileBigUploadService.checkchunk(fileMd5,chunk,chunkSize);
    }

    /**
     * 上传分块
     * @param file
     * @param chunk
     * @param fileMd5
     * @return
     */
    @PostMapping("/uploadchunk")
    public Result uploadchunk(MultipartFile file,Integer chunk,String fileMd5){
        return fileBigUploadService.uploadchunk(file,chunk,fileMd5);
    }

    /**
     * 合并文件
     * @param fileMd5
     * @param fileName
     * @param fileSize
     * @param mimetype
     * @param fileExt
     * @return
     */
    @PostMapping("/mergechunks")
    public Result mergechunks(String fileMd5,String fileName,Long fileSize,String mimetype,String fileExt){
        return fileBigUploadService.mergechunks(fileMd5,fileName,fileSize,mimetype,fileExt);
    }
}
